<template>
	<div>
		<!-- 评估历史弹窗 -->
    <el-dialog 
      title="风险评估历史"
      append-to-body
      :visible.sync="assessHistoryDialog"
      :close-on-click-modal="false" 
      :before-close="handleCloseAssessHistory"
      width="60%"
    >

      <!-- 表格内容 -->
      <avue-crud 
        :option="ahOption"
        :table-loading="ahLoading"
        :data="ahData"
        :page.sync="ahPage"
        v-model="ahForm">

        <!-- 风险等级表格自定义 -->
        <template slot="fxdj" slot-scope="scope">
          <div>{{fxdjObj[scope.row['fxdj']] || "-"}}</div>
        </template>
      </avue-crud>

      <!-- 按钮 -->
      <div class="assess_history_footer">
        <el-button 
          type="primary"
          size="small"
          @click="confirmAssessHistory()">
          确 认
        </el-button>
      </div>
    </el-dialog>
	</div>
</template>

<script>
import { getahList } from "@/api/saferisk/riskpoint";

export default {
  props: {
    assessHistoryDialog: {default: false},
    selectRiskId: {default: ""}
  },
  data() {
    return {
      ahForm: {},
      ahLoading: true,
      ahQuery: {},
      ahData: [],
      ahPage: {
        pageSize: this.$pageSize,
        currentPage: 1,
        total: 0
      },
      ahOption: {
        calcHeight: 30,
        tip: false,
        index: false,
        selection: false,
        addBtn: false,
        refreshBtn: false,
        columnBtn: false,
        menu: false,
        column: [
          {
            label: "评估时间",
            prop: "pgsj",
            align: "center"
          },
          {
            label: "评估方式",
            prop: "pgfs",
            align: "center"
          },
          {
            label: "评估描述",
            prop: "pgms",
            align: "center",
            hide: true
          },
          {
            label: "风险等级",
            prop: "fxdj",
            align: "center",
            slot: true
          },
          {
            label: "评估人",
            prop: "assessor",
            align: "center"
          },
          {
            label: "操作人",
            prop: "operator",
            align: "center"
          }
        ]
      },
      fxdjObj: {
        "1": "A",
        "2": "B",
        "3": "C",
        "4": "D"
      }
    }
  },
  watch: {
    assessHistoryDialog(){
      if(this.assessHistoryDialog === true){
        this.initData();
      }
    }
  },
  mounted() {
    this.initData();
  },
  methods: {

    // 初始化评估历史弹窗
    initData() {
      this.ahPage.currentPage = 1;
      this.ahOnLoad(this.ahPage);
    },

    // 获取评估历史列表
    ahOnLoad(page, params = {}) {
      this.ahLoading = true;
      this.ahQuery = {riskManagementId: this.selectRiskId};
      getahList(page.currentPage, page.pageSize, Object.assign(params, this.ahQuery)).then(res => {
        var resData = res.data.data;
        this.ahPage.total = resData.total;
        this.ahData = resData.records;
        this.ahLoading = false;
      });
    },

    // 确认风险评估历史
    confirmAssessHistory() {
      this.$emit('confirmAssessHistory');
    },

    // 关闭弹窗
    handleCloseAssessHistory(done) {
      done();
      this.$emit('handleCloseAssessHistory');
    }
  }
}
</script>